<template>
    <view class="containers p-bottom" v-if="goods_list.length">
		<view class="header header_wi" :style="'padding-top: ' + navH + 'px;'">
		    <view class="header_height" :style="'height:' + gaodu + 'px;line-height:' + gaodu + 'px;top:' + gaodutops + 'px;'">
		        <view class="index_h_cont3">
		            <view class="index_wenben_img" @tap="jumpzuo">
		                <image src="http://daigou.sllowly.cn/assets/api/images/dzx_img33.png" mode="widthFix"></image>
		            </view>
		            <view class="index_wenben">{{$t('checkout.title')}}</view>
		        </view>
		    </view>
		    <view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;padding-bottom: 120rpx;'">
			<!-- 顶部选项卡 -->
			  <view v-if="isShowTab" class="swiper-tab dis-flex flex-y-center flex-x-around" style="    display: flex;">
			      <view
			          :class="'swiper-tab-item ' + (curDelivery == item.value ? 'on' : '')"
			          :data-current="item.value"
			          @tap.stop.prevent="onSwichDelivery"
			          v-for="(item, index) in DeliveryTypeEnum"
			          :key="index"
			      >
			          {{ item.name }}
			      </view>
			  </view>
			
			  <!-- 快递配送：配送地址 -->
			  <view v-if="curDelivery == DeliveryTypeEnum.EXPRESS.value" @tap.stop.prevent="onSelectAddress" class="flow-delivery">
			      <view class="flow-delivery__detail dis-flex flex-y-center">
			          <view class="detail-location dis-flex">
			              <text class="iconfont icon-dingwei"></text>
			          </view>
			          <view class="detail-content flex-box" style="display: flex;align-items: center;justify-content: space-between;" @tap="genghuandizhi" :data-id="dizhixuanze.address_id">
			              <block v-if="arrlist.length>0">
							  <view class="dizhis_dis">
							  	<view class="detail-content__title dis-flex">
							  	    <text class="f-30">{{ dizhixuanze.name }}</text>
							  	    <text class="detail-content__title-phone f-28">{{ dizhixuanze.phone }}</text>
							  	</view>
							  	<view class="detail-content__describe">
							  	    <text class="col-7">{{ dizhixuanze.province }} {{ dizhixuanze.city }} {{ dizhixuanze.region }} {{ dizhixuanze.detail }}</text>
							  	</view>
							  </view>
							  <view class="dizhis_dis_img">
							  	{{$t('checkout.genghuan')}}
							  </view>
			                  
			              </block>
			              <block v-else>
			                  <view class="detail-content__describe dis-flex">
			                      <text class="col-6">{{$t('checkout.dizhi')}}</text>
			                  </view>
							  <view class="dizhis_dis_img">
							  	{{$t('checkout.xaunze')}}
							  </view>
			              </block>
			          </view>
			          <view class="detail-arrow dis-flex">
			              <text class="iconfont icon-xiangyoujiantou user-orderJtou"></text>
			          </view>
			      </view>
			  </view>
			
			  <!-- 上门自提：自提门店 -->
			  <block v-if="curDelivery == DeliveryTypeEnum.EXTRACT.value">
			      <view @tap.stop.prevent="onSelectExtractPoint" class="flow-delivery">
			          <view class="flow-delivery__detail dis-flex flex-y-center">
			              <view class="detail-location dis-flex">
			                  <text class="iconfont icon-dingwei"></text>
			              </view>
			              <view class="detail-content flex-box">
			                  <block v-if="extract_shop.shop_id">
			                      <view class="detail-content__title dis-flex">
			                          <text class="f-30">{{ extract_shop.shop_name }}</text>
			                      </view>
			                      <view class="detail-content__describe">
			                          <text class="col-7">
			                              {{ extract_shop.region.province }} {{ extract_shop.region.city }} {{ extract_shop.region.region }} {{ extract_shop.address }}
			                          </text>
			                      </view>
			                  </block>
			                  <block v-else>
			                      <view class="detail-content__describe dis-flex">
			                          <text class="col-6">{{$t('checkout.zitidian')}}</text>
			                      </view>
			                  </block>
			              </view>
			              <view class="detail-arrow dis-flex">
			                  <text class="iconfont icon-xiangyoujiantou user-orderJtou"></text>
			              </view>
			          </view>
			      </view>
			      <!-- 自提联系方式 -->
			      <view class="flow-extract-contact m-top20 b-f">
			          <view class="contact-item dis-flex">
			              <view class="item_label dis-flex flex-x-end flex-y-center">
			                  <text>{{$t('checkout.lianxiren')}}：</text>
			              </view>
			              <view class="item_ipt flex-box dis-flex flex-y-center">
			                  <input :placeholder="$t('checkout.lianxirentxt')" @input="onInputLinkman" :value="linkman" />
			              </view>
			          </view>
			          <view class="contact-item dis-flex">
			              <view class="item_label dis-flex flex-x-end flex-y-center">
			                  <text>{{$t('checkout.lianxidianhua')}}：</text>
			              </view>
			              <view class="item_ipt flex-box dis-flex flex-y-center">
			                  <input :placeholder="$t('checkout.lianxidianhuatxt')" @input="onInputPhone" :value="phone" />
			              </view>
			          </view>
			      </view>
			  </block>
			
			  <!-- 商品列表 -->
			  <view class="m-top20">
			      <view class="checkout_list" v-for="(item, index) in goods_list" :key="index">
			          <form @submit="onTargetGoods" :data-id="item.goods_id" :report-submit="true">
			              <button formType="submit" class="btn-normal">
			                  <view class="flow-shopList dis-flex" :data-index="index">
			                      <!-- 商品图片 -->
			                      <view class="flow-list-left">
			                          <image mode="scaleToFill" :src="item.goods_image"></image>
			                      </view>
			                      <view class="flow-list-right flex-box">
			                          <!-- 商品名称 -->
			                          <text class="f-30 col-3 twolist-hidden">{{ item.goods_name }}</text>
			                          <!-- 商品sku信息 -->
			                          <text class="f-24 col-7">{{ item.goods_sku.goods_attr }}</text>
			                          <!-- 商品数量和单价 -->
			                          <view class="flow-list-cont dis-flex flex-x-between flex-y-center">
			                              <text class="small">×{{ item.total_num }}</text>
			                              <text :class="'flow-cont ' + (item.is_user_grade ? 'price-delete' : '')">￥{{ item.goods_price }}</text>
			                          </view>
			                          <!-- 会员折扣价 -->
			                          <view v-if="item.is_user_grade" class="grade-price">
			                              <text>{{$t('checkout.zhekou')}}：￥{{ item.grade_goods_price }}</text>
			                          </view>
			                      </view>
			                  </view>
			              </button>
			          </form>
			      </view>
			
			      <view class="flow-num-box b-f padding-box">
			          <text>共{{ order_total_num }}{{$t('checkout.heji')}}：</text>
			          <text class="flow-money col-m">￥{{ order_total_price }}</text>
			      </view>
			  </view>
			
			  <!-- 商品金额 -->
			  <view class="flow-all-money b-f m-top20">
			      <view class="flow-all-list dis-flex">
			          <text class="flex-five">{{$t('checkout.dingdan')}}：</text>
			          <view class="flex-five t-r">
			              <text class="col-m">￥{{ order_total_price }}</text>
			          </view>
			      </view>
			      <!-- 优惠券 -->
			      <view class="flow-all-list dis-flex">
			          <text class="flex-five">{{$t('pintuandingdan.fqyouhui')}}：</text>
			          <view class="flex-five t-r">
			              <view @tap.stop.prevent="onTogglePopupCoupon">
			                  <block v-if="coupon_list.length > 0">
			                      <text class="col-m" v-if="coupon_id > 0">-￥{{ coupon_money }}</text>
			                      <text class="col-m" v-else>有{{ coupon_list.length }}{{$t('pintuandingdan.fqkeyong')}}</text>
			                      <text class="iconfont icon-xiangyoujiantou user-orderJtou"></text>
			                  </block>
			                  <text v-else class="">{{$t('pintuandingdan.fqzanwu')}}</text>
			              </view>
			          </view>
			      </view>
			      <!-- 积分抵扣 -->
			      <view v-if="is_allow_points" class="points flow-all-list dis-flex flex-y-center">
			          <view class="block-left flex-five">
			              <form class="flex-five" @submit="onShowPoints" :report-submit="true">
			                  <button formType="submit" class="btn-normal">
			                      <text class="title">{{$t('pintuandingdan.fqkeyong')}}{{ setting.points_name }}{{$t('pintuandingdan.fqdikou')}}：</text>
			                      <text class="iconfont icon-help"></text>
			                  </button>
			              </form>
			          </view>
			          <view class="flex-five dis-flex flex-x-end flex-y-center">
			              <text class="points-money col-m">￥{{ points_money }}</text>
			              <van-switch :checked="isUsePoints" size="48rpx" active-color="#07c160" @change="onTriggerPoints" />
			          </view>
			      </view>
			      <!-- 配送费用 -->
			      <!-- <view v-if="curDelivery == DeliveryTypeEnum.EXPRESS.value" class="dis-flex flow-all-list">
			          <text class="flex-five">配送费用：</text>
			          <view class="flex-five t-r">
			              <view v-if="address.address_id">
			                  <text class="col-m" v-if="intra_region">+￥{{ express_price }}</text>
			                  <text v-else>不在配送范围</text>
			              </view>
			              <view v-else>
			                  <text class="col-7">请先选择配送地址</text>
			              </view>
			          </view>
			      </view> -->
			  </view>
			
			  <!-- 支付方式 -->
			  <view class="pay-method flow-all-money b-f m-top20">
			      <view class="flow-all-list dis-flex">
			          <text class="flex-five">{{$t('pintuandingdan.fqzhifu')}}</text>
			      </view>
			      <form @submit="onSelectPayType" :data-value="PayTypeEnum.WECHAT.value" :report-submit="true">
			          <button formType="submit" class="btn-normal">
			              <view class="pay-item pay-method_dis dis-flex flex-x-between">
			                  <view class="item-left dis-flex flex-y-center">
			                      <view class="item-left_icon wechat">
			                          <text class="iconfont icon-weixinzhifu"></text>
			                      </view>
			                      <view class="item-left_text">
			                          <text>{{ PayTypeEnum.WECHAT.name }}</text>
			                      </view>
			                  </view>
			                  <view class="item-right col-m method_dis_dis" v-if="curPayType == PayTypeEnum.WECHAT.value">
			                      <image style="width: 20px;height: 20px;" src="http://daigou.sllowly.cn/assets/api/selected.png"></image>
			                  </view>
			              </view>
			          </button>
			      </form>
			      <form @submit="onSelectPayType" :data-value="PayTypeEnum.BALANCE.value" :report-submit="true">
			          <button formType="submit" class="btn-normal">
			              <view class="pay-item pay-method_dis dis-flex flex-x-between">
			                  <view class="item-left dis-flex flex-y-center">
			                      <view class="item-left_icon balance">
			                          <text class="iconfont icon-qiandai"></text>
			                      </view>
			                      <view class="item-left_text">
			                          <text>{{ PayTypeEnum.BALANCE.name }}</text>
			                      </view>
			                  </view>
			                  <view class="item-right col-m method_dis_dis" v-if="curPayType == PayTypeEnum.BALANCE.value">
			                      <image style="width: 20px;height: 20px;" src="http://daigou.sllowly.cn/assets/api/selected.png"></image>
			                  </view>
			              </view>
			          </button>
			      </form>
			  </view>
			
			  <!-- 买家留言 -->
			  <view class="flow-all-money b-f m-top20">
			      <view class="ipt-wrapper dis-flex flow-all-list">
			          <input @input="bindRemark" :placeholder="$t('pintuandingdan.fqliuyan')" :value="remark" />
			      </view>
			  </view>
			
			  <!-- 提交订单 -->
			  <view class="flow-fixed-footer b-f m-top10">
			      <view class="dis-flex chackout-box" style="display: flex;align-items: center;">
			          <view class="chackout-left pl-12">
			              {{$t('pintuandingdan.fqshifukuan')}}：
			              <text class="col-m">￥{{ order_pay_price }}</text>
			          </view>
			          <view @tap.stop.prevent="onSubmitOrder" class="chackout-right">
			              <text class="flow-btn f-32">{{$t('pintuandingdan.fqtijiao')}}</text>
			          </view>
			      </view>
			  </view>
			
			  <!-- 优惠券弹出框 -->
			  <zan-popup :show="showBottomPopup" type="bottom" @close="onTogglePopupCoupon">
			      <view class="popup__coupon">
			          <view class="coupon__title f-32">{{$t('pintuandingdan.fqxuanzeyouhuiq')}}</view>
			
			          <!-- 优惠券列表 -->
			          <view class="coupon-list">
			              <scroll-view :scroll-y="true" style="height: 565rpx">
			                  <view class="coupon-item" v-for="(item, index) in coupon_list" :key="index">
			                      <view :class="'item-wrapper color__' + item.color.text" @tap.stop.prevent="onSelectCoupon" :data-index="index" :data-id="item.user_coupon_id">
			                          <view class="coupon-type">{{ item.coupon_type.text }}</view>
			                          <view class="tip dis-flex flex-dir-column flex-x-center">
			                              <view v-if="item.coupon_type.value == 10">
			                                  <text class="f-30">￥</text>
			                                  <text class="money">{{ item.reduce_price }}</text>
			                              </view>
			                              <text class="money" v-if="item.coupon_type.value == 20">{{ item.discount }}{{$t('pintuandingdan.fqzhe')}}</text>
			                              <text class="pay-line">{{$t('pintuandingdan.fqman')}}{{ item.min_price }}{{$t('pintuandingdan.fqyuankeyong')}}</text>
			                          </view>
			                          <view class="split-line"></view>
			                          <view class="content dis-flex flex-dir-column flex-x-between">
			                              <view class="title">{{ item.name }}</view>
			                              <view class="bottom dis-flex flex-y-center">
			                                  <view class="time flex-box">
			                                      <text>{{$t('pintuandingdan.fqyouxaioqi')}}：{{ item.start_time.text }}~{{ item.end_time.text }}</text>
			                                  </view>
			                                  <!-- <view class="state flex-box">
			              <text>-￥{{ item.reduced_price }}</text>
			            </view> -->
			                              </view>
			                          </view>
			                      </view>
			                  </view>
			              </scroll-view>
			          </view>
			
			          <!-- 不使用优惠券 -->
			          <view class="coupon__do_not dis-flex flex-y-center flex-x-center">
			              <view class="control dis-flex flex-y-center flex-x-center" @tap.stop.prevent="onNotUseCoupon">
			                  <text class="f-26">{{$t('pintuandingdan.fqbushiyong')}}</text>
			              </view>
			          </view>
			          <!-- <view class="footer-fixed f-32">
			  <view catchtap="onTogglePopupCoupon" class="order-bt" style="width:100%">关闭</view>
			</view> -->
			      </view>
			  </zan-popup>
			
			  <!-- 积分说明弹框 -->
			  <zan-dialog id="zan-base-dialog"></zan-dialog>
			
		</view>
        
    </view>

    <!-- 快捷导航 -->
    <!-- <shortcut></shortcut> -->
</template>

<script>
import zanPopup from '@/components/popup/index.vue';
import zanDialog from '@/components/dialog/index.vue';
// import vanSwitch from '@/components/switch/index.vue';
// import shortcut from '@/components/shortcut/shortcut.vue';
const app = getApp(); // 工具类
import Util from '../../utils/util.js'; // 验证类
import Verify from '../../utils/verify.js'; // 枚举类：发货方式
import DeliveryTypeEnum from '../../utils/enum/DeliveryType.js'; // 枚举类：支付方式
import PayTypeEnum from '../../utils/enum/order/PayType'; // 对话框插件
import Dialog from '../../components/dialog/dialog';
let request = require('../../utils/require');
export default {
    components: {
        zanPopup,
        zanDialog,
        // vanSwitch,
        // shortcut
    },
    data() {
        return {
			navH: app.globalData.navHeight,
			gaodu: app.globalData.height,
			gaodutops: app.globalData.top,
            // 当前页面参数
            options: {},

            // // 系统设置：配送方式
            // deliverySetting: [],
            // 系统设置
            setting: {
                // 支持的配送方式
                delivery: [],

                points_name: ''
            },

            // 配送方式
            isShowTab: false,

            DeliveryTypeEnum,
            curDelivery: null,

            // 支付方式
            PayTypeEnum,

            curPayType: PayTypeEnum.BALANCE.value,
            address: null,

            // 默认收货地址
            exist_address: false,

            // 是否存在收货地址
            selectedShopId: 0,

            // 选择的自提门店id
            linkman: '',

            // 自提联系人
            phone: '',

            // 自提联系电话
            // 商品信息
            goods: {},

            // 选择的优惠券
            selectCouponId: 0,

            // 是否使用积分抵扣
            isUsePoints: false,

            // 买家留言
            remark: '',

            // 禁用submit按钮
            disabled: false,

            has_error: false,
            error_msg: '',

            // 不允许刷新
            notRefresh: false,

            showBottomPopup: false,

            goods_list: {
                length: ''
            },

            value: '',
            province: '',
            city: '',
            region: '',

            extract_shop: {
                shop_id: '',
                shop_name: '',

                region: {
                    province: '',
                    city: '',
                    region: ''
                },

                address: ''
            },

            order_total_num: 0,
            order_total_price: '',

            coupon_list: {
                length: 0
            },

            coupon_id: 0,
            coupon_money: '',
            is_allow_points: [],
            points_money: '',
            intra_region: '',
            express_price: '',
            name: '',
            order_pay_price: '',
			
			address_id:'',
			dizhixuanze:{},
			arrlist:[]
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let _this = this; // 当前页面参数
        _this.options = options;
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let that = this; // 获取当前订单信息
        if (!that.notRefresh) {
            that.getOrderData();
        }
		let pages = getCurrentPages();
		let currPage = pages[pages.length - 1];
		// #ifdef MP-WEIXIN
		if (currPage.data && currPage.data.address_id) {
			console.log(that.currentTab,88787)
			if (this.currentTab == 1) {
				
				this.address_id = currPage.data.address_id
				var item={}
				for(var i=0;i<that.arrlist.length;i++){
				   if(that.arrlist[i].address_id==currPage.data.address_id){
					   item = that.arrlist[i]
				   }
				}
				that.dizhixuanze = item;
				
			} else if (this.currentTab == 2 && currPage.data.ischoose == 2) {
				this.address_zt_id = currPage.data.address_id
			}
		}
		// #endif
		// #ifdef H5
		if (currPage.address_id) {
		   var item={}
		   for(var i=0;i<that.arrlist.length;i++){
			   if(that.arrlist[i].address_id==currPage.address_id){
				   item = that.arrlist[i]
			   }
		   }
		   that.address_id = currPage.address_id,
		   that.dizhixuanze =item
		}
		// #endif
		that.dizhilist()
    },
    methods: {
		dizhilist() {
		    var that = this;
		    var data = {
		        token: uni.getStorageSync('token')
		    };
		    request.post(`index.php?s=/api/address/lists&wxapp_id=` + uni.getStorageSync('web_id'), data).then((res) => {
		        if (res.data.code == 1) {
					that.arrlist = res.data.data.list,
					that.address_id = res.data.data.list[0].address_id,
					that.dizhixuanze = res.data.data.list[0]
		        }
		    });
		},
		genghuandizhi() {
		    //跳转选择地址
		    uni.navigateTo({
		        url: '/pages/pintuans/dizhi/dizhi?type=xuanze'
		    });
		},
		jumpzuo() {
		    uni.navigateBack()
		},
        /**
         * 获取当前订单信息
         */
        getOrderData() {
            let _this = this;
            let options = _this.options; // 获取订单信息回调方法
            let callback = (result) => {
                let resData = result.data; // 请求错误
                if (result.code !== 1) {
                    app.globalData.showError(result.msg);
                    return false;
                } // 显示错误信息
                let data = {}; // 当前选择的配送方式
                data.curDelivery = resData.delivery; // 如果只有一种配送方式则不显示选项卡
                data.isShowTab = resData.setting.delivery.length > 1; // 上门自提联系信息
                if (_this.linkman === '') {
                    data.linkman = resData.last_extract.linkman;
                }
                if (_this.phone === '') {
                    data.phone = resData.last_extract.phone;
                } // 设置页面数据
                _this.setData(Object.assign({}, resData, data));
                uni.hideLoading();
            };

            uni.showLoading({
                title:_this.$t('m.jiazai')+'...'
            }); // 请求的参数

            let params = {
                delivery: _this.curDelivery || 0,
                shop_id: _this.selectedShopId || 0,
                coupon_id: _this.selectCouponId || 0,
                is_use_points: _this.isUsePoints ? 1 : 0
            }; // 立即购买

            if (options.order_type === 'buyNow') {
                app.globalData._get(
                    'order/buyNow',
                    Object.assign({}, params, {
                        goods_id: options.goods_id,
                        goods_num: options.goods_num,
                        goods_sku_id: options.goods_sku_id
                    }),
                    (result) => {
                        callback(result);
                    }
                );
            } // 砍价活动结算
            else {
                if (options.order_type === 'bargain') {
                    app.globalData._get(
                        'bargain.order/checkout',
                        Object.assign({}, params, {
                            task_id: options.task_id,
                            goods_sku_id: options.goods_sku_id
                        }),
                        (result) => {
                            callback(result);
                        }
                    );
                } // 秒杀活动结算
                else {
                    if (options.order_type === 'sharp') {
                        app.globalData._get(
                            'sharp.order/checkout',
                            Object.assign({}, params, {
                                active_time_id: options.active_time_id,
                                sharp_goods_id: options.sharp_goods_id,
                                goods_sku_id: options.goods_sku_id,
                                goods_num: options.goods_num
                            }),
                            (result) => {
                                callback(result);
                            }
                        );
                    } // 购物车结算
                    else {
                        if (options.order_type === 'cart') {			
							var data = {
								  cart_ids: options.cart_ids || 0,
								  token: uni.getStorageSync('token')
							}
							request.get(`index.php?s=/api/order/cart&wxapp_id=` + uni.getStorageSync('web_id'), data).then((res) => {
							    if (res.data.code == 1) {
									callback(result);
							    } else {
							        uni.showToast({
							            title: res.data.msg,
							            icon: 'none'
							        });
							    }
							});
                        }
                    }
                }
            }
        },

        /**
         * 切换配送方式
         */
        onSwichDelivery(e) {
            // 设置当前配送方式
            let _this = this;
            _this.curDelivery = e.currentTarget.dataset.current
            _this.getOrderData();
        },

        /**
         * 快递配送：选择收货地址
         */
        onSelectAddress() {
            let _this = this; // 允许刷新
            _this.notRefresh = false
            // 跳转到选择自提点
            uni.navigateTo({
                url: '../address/' + (_this.exist_address ? 'index?from=flow' : 'create')
            });
        },

        /**
         * 上门自提：选择自提点
         */
        onSelectExtractPoint() {
            let _this = this;
            let selectedId = _this.selectedShopId; // 允许刷新
            _this.notRefresh =  false
          // 跳转到选择自提点

            uni.navigateTo({
                url: '/pages/pintuans/dsdizhi/dizhi?type=xuanze'
            });
        },
        /**
         * 跳转到商品详情页
         */
        onTargetGoods(e) {
            uni.navigateTo({
                url: `../goods/index?goods_id=${e.currentTarget.dataset.id}`
            });
        },

        /**
         * 订单提交
         */
        onSubmitOrder() {
            let _this = this;
			
            let options = _this.options;
            if (_this.disabled) {
                return false;
            } // 表单验证

            if (!_this._onVerify()) {
                return false;
            } // 按钮禁用, 防止二次提交

            _this.disabled = true;
            let url = ''; // 表单提交的数据

            let postData = {
                delivery: _this.curDelivery,
                pay_type: _this.curPayType,
                shop_id: _this.selectedShopId || 0,
                linkman: _this.linkman,
                phone: _this.phone,
                coupon_id: _this.selectCouponId || 0,
                is_use_points: _this.isUsePoints ? 1 : 0,
                remark: _this.remark || '',
				address_id:_this.address_id
            }; // 创建订单-立即购买

            if (options.order_type === 'buyNow') {
                url = 'order/buyNow';
				
                postData = Object.assign(postData, {
                    goods_id: options.goods_id,
                    goods_num: options.goods_num,
                    goods_sku_id: options.goods_sku_id
                });
            } // 创建订单-购物车结算

            if (options.order_type === 'cart') {
                url = 'order/cart';
                postData = Object.assign(postData, {
                    cart_ids: options.cart_ids || 0
                });
            } // 创建订单-砍价活动

            if (options.order_type === 'bargain') {
                url = 'bargain.order/checkout';
                postData = Object.assign(postData, {
                    task_id: options.task_id,
                    goods_sku_id: options.goods_sku_id
                });
            } // 创建订单-秒杀商品

            if (options.order_type === 'sharp') {
                url = 'sharp.order/checkout';
                postData = Object.assign(postData, {
                    active_time_id: options.active_time_id,
                    sharp_goods_id: options.sharp_goods_id,
                    goods_sku_id: options.goods_sku_id,
                    goods_num: options.goods_num
                });
            } // 提交到后端
console.log(options.order_type,2222)
            const onCommitCallback = () => {
                // 显示loading
                uni.showLoading({
                    title: '正在处理...'
                }); // 订单提交
console.log(options.order_type,11111111)
                app.globalData._post_form(
                    url,
                    postData,
                    (result) => {
                        _this._onSubmitCallback(result);
                    },
                    (result) => {},
                    () => {
                        uni.hideLoading(); // 解除按钮禁用

                        _this.disabled = false;
                    }
                ); // 不允许刷新

                _this.notRefresh = true
            }; // 请求用户订阅消息
			onCommitCallback();
        },

        /**
         * 请求用户订阅消息
         */
        _onRequestSubscribeMessage(onCommitCallback) {
            let _this = this;

            let tmplIds = _this.setting.order_submsg;
            if (tmplIds.length == 0) {
                onCommitCallback();
                return;
            }

            uni.requestSubscribeMessage({
                tmplIds,

                success(res) {},

                fail(res) {},

                complete(res) {
                    onCommitCallback();
                }
            });
        },

        /**
         * 订单提交成功后回调
         */
        _onSubmitCallback(result) {
            let _this = this; // 订单创建成功后回调--微信支付

            if (result.code === -10) {
                app.globalData.showError(result.msg, () => {
                    _this.redirectToOrderIndex();
                });
                return false;
            } // 发起微信支付

            if (result.data.pay_type == PayTypeEnum.WECHAT.value) {
                app.globalData.wxPayment({
                    payment: result.data.payment,
                    success: (res) => {
                        _this.redirectToOrderIndex();
                    },
                    fail: (res) => {
                        app.globalData.showError(result.msg.error, () => {
                            _this.redirectToOrderIndex();
                        });
                    }
                });
            } // 余额支付

            if (result.data.pay_type == PayTypeEnum.BALANCE.value) {
                app.globalData.showSuccess(result.msg.success, () => {
                    _this.redirectToOrderIndex();
                });
            }
        },

        /**
         * 表单验证
         */
        _onVerify() {
            let _this = this;

           
            if (_this.curDelivery == DeliveryTypeEnum.EXTRACT.value) {
                _this.linkman = _this.linkman.trim()
                _this.phone = _this.phone.trim()
				
                if (_this.selectedShopId <= 0) {
                    app.globalData.showError(_this.$t('pintuandingdan.fqmendian'));
                    return false;
                }

                if (Verify.isEmpty(_this.linkman)) {
                    app.globalData.showError(_this.$t('pintuandingdan.fqziti'));
                    return false;
                }

                if (Verify.isEmpty(_this.phone)) {
                    app.globalData.showError(_this.$t('pintuandingdan.fqzitidianhua'));
                    return false;
                }

                if (!Verify.isPhone(_this.phone)) {
                    app.globalData.showError(_this.$t('pintuandingdan.fqzhengquedianhua'));
                    return false;
                }
            }

            return true;
        },

        /**
         * 买家留言
         */
        bindRemark(e) {
            let _this = this;
            _this.remark = e.detail.value;
        },

        /**
         * 选择优惠券(弹出/隐藏)
         */
        onTogglePopupCoupon() {
            let _this = this;
            if (_this.coupon_list.length > 0) {
                _this.showBottomPopup = !_this.showBottomPopup
            }
        },

        /**
         * 选择优惠券
         */
        onSelectCoupon(e) {
            let _this = this; // 记录选中的优惠券id
            _this.selectCouponId = e.currentTarget.dataset.id// 重新获取订单信息
            _this.getOrderData(); // 隐藏优惠券弹层
            _this.onTogglePopupCoupon();
        },

        /**
         * 不使用优惠券
         */
        onNotUseCoupon() {
            let _this = this;
            _this.selectCouponId = 0 ;
            _this.getOrderData(); // 隐藏优惠券弹层
            _this.onTogglePopupCoupon();
        },

        /**
         * 选择支付方式
         */
        onSelectPayType(e) {
            let _this = this; // 记录formId
            app.globalData.saveFormId(e.detail.formId); // 设置当前支付方式
            _this.curPayType =  e.currentTarget.dataset.value
        },

        /**
         * 跳转到未付款订单
         */
        redirectToOrderIndex() {
            uni.redirectTo({
                url: '../order/index'
            });
        },

        /**
         * input绑定：联系人
         */
        onInputLinkman(e) {
            let _this = this;
            _this.linkman = e.detail.value
        },

        /**
         * input绑定：联系电话
         */
        onInputPhone(e) {
            let _this = this;
            _this.phone = e.detail.value
        },

        /**
         * 选择积分抵扣
         */
        onTriggerPoints({ detail }) {
            let _this = this;
            _this.isUsePoints = detail; // 重新获取订单信息
            _this.getOrderData();
        },

        /**
         * 显示积分说明
         */
        onShowPoints(e) {
            let _this = this; // 记录formId

            app.globalData.saveFormId(e.detail.formId); // 显示dialog

            let setting = _this.setting;
            Dialog({
                title: `${setting.points_name}`+_this.$t('pintuandingdan.fqshuoming'),
                message: setting.points_describe,
                selector: '#zan-base-dialog',
                isScroll: true,
                // 滚动
                buttons: [
                    {
                        text: _this.$t('pintuandingdan.fqguanbi'),
                        color: 'red',
                        type: 'cash'
                    }
                ]
            });
        }
    }
};
</script>
<style>
@import './checkout.css';
</style>
